<?php if (!defined('LEGAL_INNER_USE')){die('ILLEGAL USING!');}?>
<?php
$pID = isset($_GET['pID'])?trim($_GET['pID'])*1:0;
$sql = "SELECT goods_id, cat_id,  goods_sn,   goods_name, shop_price, keywords,  goods_desc, goods_img, original_img FROM ".DB_PRE.DB_PRE_ECSHOP."goods WHERE goods_id = $pID LIMIT 1";
$good = $db -> execute($sql);
if ($good -> recordCount()<1){
	$pID = 0;
}

if ($pID == 0){
	#404
	jumpTo(makeUrl('404'), '404');
	exit;
} else {
	$cateId = $good -> fields['cat_id']*1;
	$goods_id = $good -> fields['goods_id']*1;
	$goods_sn = trim($good -> fields['goods_sn']);
	$goods_name = trim($good -> fields['goods_name']);
	$shop_price = trim($good -> fields['shop_price']);
	$meta_keywords = $keywords = trim($good -> fields['keywords']);
	$goods_desc = trim($good -> fields['goods_desc']);
	#echo $goods_name;exit;
	$goods_img = trim($good -> fields['goods_img']);
	$original_img = trim($good -> fields['original_img']);
	#相册
	$sql = "SELECT img_original FROM ".DB_PRE.DB_PRE_ECSHOP."goods_gallery WHERE goods_id = $pID ORDER BY img_desc DESC";
	$goods_gallery = diy_execute($sql, 'img_original');
	#dump($goods_gallery);
	
	$catesPath = $categories -> ExtTreeData2($catesSorted);
	if (isset($catesPath[$cateId]) && !empty($catesPath[$cateId])){
		#print_r($catesPath[$cateId]);
		foreach($catesPath[$cateId] as $v){
			$breadcrumb .= '<li><span class="divider">/</span><a href="'.makeUrl("products", "cateId=".$v["cat_id"]).'">'.$v['cat_name'].'</a></li>';
		}
		$breadcrumb .= '<li><span class="divider">/</span>'.$goods_name.'</li>';
	}
	
	$addTitle = trim($goods_name);
	unset($catesPath);
	
	#keywords 2 search
	$keywords = array_unique(explode(',', str_replace(array(' ', ',','，'), ',', trim($keywords))));
	if (!empty($keywords) && trim($keywords[0]) != ''){
		$r = '';
		foreach($keywords as $v){
			$r .= '<a href="'.makeUrl("searchResult", "k=".htmlspecialchars($v)).'">'.$v.'</a> ';
		}
		$keywords = $r;
	} else {
		$keywords = '-';
	}
	
	#属性描述
	$sql = "SELECT a.attr_name, ga.attr_value FROM ".DB_PRE.DB_PRE_ECSHOP."goods_attr ga LEFT JOIN ".DB_PRE.DB_PRE_ECSHOP."attribute a ON a.attr_id = ga.attr_id WHERE ga.goods_id = $goods_id";
	$products_desc_attrs = diy_execute($sql);
}


